package kz.edu.sdu.atm.ui.client;

import kz.edu.sdu.atm.client.Client;

import com.trolltech.qt.gui.QHBoxLayout;
import com.trolltech.qt.gui.QLabel;
import com.trolltech.qt.gui.QLineEdit;
import com.trolltech.qt.gui.QPushButton;
import com.trolltech.qt.gui.QVBoxLayout;
import com.trolltech.qt.gui.QWidget;

public class Form extends QMyWidget {
	public Signal1<Integer> twoFields = new Signal1<Integer>();
	public Signal1<Integer> oneField = new Signal1<Integer>();
	public Signal1<Integer> deposit = new Signal1<Integer>();
	public Signal1<Integer> withdraw = new Signal1<Integer>();
	public Signal1<Integer> send = new Signal1<Integer>();
	public Signal1<Integer> curSignal;

	QLineEdit amount, to;
	QPushButton ok, cancel;
	QLabel toLabel;
	QWidget p;

	public Form(QWidget parent, Client client) {
		super(null, client);
		p = parent;
	}
	@Override
	void connectAll() {
		cancel.clicked.connect(this, "back()");
		// twoFields.connect(this, "enableBoth()");
		// twoFields.connect(this, "enableOne()");
		ok.clicked.connect(this, "ok()");
	}

	public void ok(){
		curSignal.emit(2);
		back();
	}

	public void enableBoth(boolean ok) {
		toLabel.setVisible(ok);
		to.setVisible(ok);
	}

	public void deposit() {
		enableOne();
		System.out.println("DEPOSIT");
		curSignal = deposit;
	}

	public void withdraw() {
		enableOne();
		System.out.println("WITH");
		curSignal = withdraw;
	}

	public void send() {
		enableBoth();
		System.out.println("SEND");
		curSignal = send;
	}

	public void enableBoth() {
		enableBoth(true);
	}

	public void enableOne() {
		enableBoth(false);
	}
	public void back() {
		hide();
		p.show();
	}

	@Override
	void init() {
		// TODO Auto-generated method stub
		amount = new QLineEdit();
		to = new QLineEdit();
		ok = new QPushButton("Ok");
		cancel = new QPushButton("Cancel");
		setFixedSize(400, 200);
		layout = new QVBoxLayout();
		layout.addWidget(new QLabel("Amount:"));
		layout.addWidget(amount);
		toLabel = new QLabel("To:");
		layout.addWidget(toLabel);
		layout.addWidget(to);

		QHBoxLayout buttonLayout = new QHBoxLayout();
		buttonLayout.addWidget(ok);
		buttonLayout.addWidget(cancel);
		layout.addItem(buttonLayout);

		setLayout(layout);
	}

}
